import OrderItem from "../OrderItem.tsx";
import {useState, useEffect} from "react";
import Order from "../../../model/Order.ts";
import {baseUrl} from "../../../settings/Settings.ts";


const OrderFragment = () => {

    const [orderList, setOrderList] = useState<Order>()

    //TODO rewrite this function to fetch order data from the server and use setOrderList to
    //set order list
    useEffect(() => {
        const fetchData = async () => {
            try {
                const response = await fetch(`${baseUrl}/api/library/info`, {
                    method: 'GET',
                    headers: {
                        'Access-Control-Allow-Origin': '*',
                        'Access-Control-Allow-Headers': 'Content-Type, Accept, Origin, X-Requested-With',
                        'Content-Type': 'application/json'
                    }
                });
                const data = await response.json();
                console.log(data)
                setCategoryList(data.categories)
            } catch (error) {
                console.error('Error fetching data')
            }
        }

        fetchData();
    }, []);

    return (
        <div className="container mt-0 p-0 pb-1 mb-5" id="container-items-list">

            <OrderItem/>
        </div>

    )
}

export default OrderFragment